T_set=[175 195 235 255];v=65;
s=0;i=1;N=30000;
while(s<N)
    x=rand(1,5);
    T_set0=T_set+(x(1:4)-0.5)*20;v0=v+35*x(5);
    [t,T,~]=main(T_set0,v0);
    flag=limit(t,T);
        S(i)=area(t,T)*flag;
        if(S(i)==0)%不符合制程要求
            S(i)=inf;
        end
        minS(i)=min(S);
        if(i==1)
            T_set1=T_set0;v1=v0;Smin=minS(1);
        else
            if(minS(i)<minS(i-1))%迭代更新最小面积
                T_set1=T_set0;v1=v0;s=0;Smin=minS(i);
            else
                s=s+1;
            end
        end
        i=i+1;
end
figure
plot(1:length(minS),minS,'k');
xlabel('迭代次数')
ylabel('最小面积')
title(['S_{min}=',num2str(Smin)])
[t,T,~]=main(T_set0,v0);
figure
[~,k1]=min(abs(T-217));
[Tmax,k2]=max(T);
ts1=t(k1(1):k2);
Ts1=217*ones(size(ts1));
Ts2=T(k1(1):k2);
ts2=t(k2)*ones(size(Ts2));
ts3=ts1;
Ts3=T(k1(1):k2);
ts=[ts1;ts2;ts3];
Ts=[Ts1;Ts2;Ts3];
plot(t,T,'k')
xlabel('时间/s')
ylabel('温度/℃')
% hold on
% plot(ts1,Ts1,'k:',ts2,Ts2,'k:')
hold on
fill(ts,Ts,'k')
title(['S_{min}=',num2str(Smin)])